//app.js
App({
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    var that = this
    wx.login({
      success: function (res) {
        if (res.code) {
          //console.log(res.code)          //发起网络请求
          wx.request({
            url: 'https://xcx.chenjiudenanren.com/inter/Sy/login',
            data: {
              code: res.code,
             // code: res.code,
              //code: res.code
            },
            success: function (res) {
              that.globalData.tabnum = res.data.status
             
              wx.setStorage({
                key: "trd_session",
                data: res.data.wxid,
              })
              wx.setStorage({
                key: "tabnum",
                data: res.data.status,
              })


            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    });

  },

  getUserInfo: function (cb) {
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //发起网络请求
      wx.getUserInfo({
        success: function (res) {
          var userf = res.userInfo
          console.log(res)
          //console.log(userf.nickName)
          wx.setStorageSync('nickName', userf.nickName)
          that.globalData.userInfo = res.userInfo
          typeof cb == "function" && cb(that.globalData.userInfo)
        }
      })
    }
  },
  globalData: {
    userInfo: null,
    URL: "https://xcx.chenjiudenanren.com",
    tabnum: null,// 0普通用户的导航 1执法者
  }
})